package ch.usi.inf.pf2.editor;

import ch.usi.inf.pf2.Sheet;
import ch.usi.inf.pf2.cell.Cell;
import junit.framework.TestCase;
/**
 * 
 * @author Lorenzo Baracchi <lorenzo.baracchi@usi.ch>
 *
 */
public class TestPaste extends TestCase
{
    private Sheet s;
    private Cell c1;
    private Cell c2;
    private Paste ps;
    private Copy cp;
    private Cut ct;
    
    protected void setUp ()
    {
	   s=new Sheet();
	   s.initializeSheet();
	   c1=s.getCell(1, 1);
	   c1.setContent("hi");
	   c2=s.getCell(2, 2);   
	   c2.setContent("");
	   cp = new Copy(s, 1, 1);
	   ct = new Cut(s, 1, 1);
    }
    
    public void testEvaluateWithCopy ()
    {
	   cp.evaluate();
	   try
	   {
		  ps=new Paste(s, 2, 2, cp);
		  assertEquals("", c2.getContent().toString());
	   } catch (Exception e)
	   {
		  // TODO Auto-generated catch block
		e.printStackTrace();
	   }
	   ps.evaluate();
	   assertEquals("", ps.getOldText());
	   assertEquals("hi", ps.getNewText());
	   assertEquals("hi", c2.getContent().toString());
	   assertEquals("hi", c1.getContent().toString());	   
    }
    
    public void testRestoreWithCopy ()
    {
	   cp.evaluate();
	   try
	   {
		  ps=new Paste(s, 2, 2, cp);
	   } catch (Exception e)
	   {
		  // TODO Auto-generated catch block
		e.printStackTrace();
	   }
	   ps.evaluate();
	   ps.restore();
	   assertEquals("", ps.getOldText());
	   assertEquals("hi", ps.getNewText());
	   assertEquals("", c2.getContent().toString());
	   assertEquals("hi", c1.getContent().toString());	  
    }   
    
    public void testEvaluateWithCut ()
    {
	   ct.evaluate();
	   try
	   {
		  ps=new Paste(s, 2, 2, ct);
	   } catch (Exception e)
	   {
		  // TODO Auto-generated catch block
		e.printStackTrace();
	   }
	   ps.evaluate();
	   assertEquals("", ps.getOldText());
	   assertEquals("hi", ps.getNewText());
	   assertEquals("hi", c2.getContent().toString());
	   assertEquals("", c1.getContent().toString());	   
    }
    
    public void testRestoreWithCut ()
    {
	   ct.evaluate();
	   try
	   {
		  ps=new Paste(s, 2, 2, ct);
	   } catch (Exception e)
	   {
		  // TODO Auto-generated catch block
		e.printStackTrace();
	   }
	   ps.evaluate();
	   ps.restore();
	   assertEquals("", ps.getOldText());
	   assertEquals("hi", ps.getNewText());
	   assertEquals("", c2.getContent().toString());
	   assertEquals("", c1.getContent().toString());	  
    }   
}
